package com.pro.config;

import com.pro.pojo.JsUser;
import com.pro.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

/**
 * @author ：刘弘禹
 * @description：TODO
 * @date ： 2022/1/9 14:42
 */
@Component
public class SecurityServiceImple implements UserDetailsService {
    @Autowired
    private LoginService loginService;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        JsUser login = loginService.login(username, null);
        if (login == null){
            throw new UsernameNotFoundException("用户名错误");
        }
        org.springframework.security.core.userdetails.User result = new org.springframework.security.core.userdetails.User(
                username,login.getPassword(), AuthorityUtils.createAuthorityList()
        );
        return result;
    }



}
